Repository navigation
Conversation
BigInteger maps to numeric, so `/` between two BigInteger values ran as numeric division in PostgreSQL and returned 3.5 for 7 / 2. .NET truncates towards zero and returns 3. Translate the division to div(a, b), which truncates the same way. Fixes npgsql#4143
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4143
BigIntegermaps tonumeric, so/between twoBigIntegervalues was sent to PostgreSQL as numeric division. For 7 / 2 that returns 3.5, while .NET returns 3.This translates
/todiv(a, b)when both operands areBigInteger(nullable included).divtruncates towards zero, likeBigIntegerdivision in .NET. Division by zero fails in both cases. The change sits inNpgsqlSqlTranslatingExpressionVisitor.VisitBinary, next to the existingLocalDatesubtraction case.Before:
After:
Tests added to
BigIntegerTranslationsTest:Divide:/ 2 == 1returns the rows with 2 and 3. Numeric division only returned 2.Divide_truncates_towards_zero:/ 2 == 0returns the rows with 0, 1 and -1, so negative values are covered.Divide_with_parameter: the divisor is a parameter.BigInteger.Divide(a, b)still has no translation. Should I add it to this PR as well, or keep that separate?